package com.schedualnew.mq.util;


import java.util.Arrays;
import java.util.HashMap;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class BASE64 {
    public static String encode(byte[] key) throws Exception {
        String s = null;
        if (key != null) {
            s = (new BASE64Encoder()).encode(key);
        }
        return s;
    }


    public static byte[] decode(String s) throws Exception {
        byte[] b = null;
        if (s != null) {

            BASE64Decoder decoder = new BASE64Decoder();
            try {
                b = decoder.decodeBuffer(s);
                return b;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return b;
    }

    public static void main(String[] args) throws Exception {
        HashMap<String, String> map = new HashMap<>();
        map.put("0201", "c");
        map.put("0101", "b");
        map.put("0304", "d");
        map.put("0001", "a");

        Object[] keys = map.keySet().toArray();
        Arrays.sort(keys);

        for (Object k : keys) {
            System.out.println(map.get(k));
        }
        String s = "福建中医学院附属人民医院";
        System.out.println("base64编码前：" + s);
        byte[] b = s.getBytes();
        String base = encode(b);


        System.out.println("md5编码后：" + MD5Utils.getMD5(base));
    }
}
